﻿@model IList<Shopping_cart.Models.Product>
@functions {private decimal GetDiscount(int numberOfItems)
    {
        if (numberOfItems <= 2)
        {
            return (decimal)0.05;
        }
        if (numberOfItems > 2 && numberOfItems <= 4)
        {
            return (decimal)0.1;
        }
        return (decimal)0.15;
    }
}
@{
    ViewBag.Title = "Reciept";
}
<h2>
    Reciept</h2>
<form action="@Url.Action("Payment")" method="post">
    <table>
        <tr>
            <td>
                Name
            </td>
            <td>
                Price
            </td>
        </tr>
        @foreach (var product in Model)
        {
            <tr>
                <td>
                    @product.Name
                </td>
                <td>
                    @product.Price
                </td>
            </tr>
        }
        <tr>
            <td>
                <b>Total Before Tax</b>
            </td>
            @{
                decimal totalbefore = Model.Sum(x => x.Price);
            }
            <td>@totalbefore
            </td>
        </tr>
        <tr>
            <td>
                <b>Tax(10%)</b>
            </td>
            @{
                decimal tax = Model.Sum(x => x.Price) * (decimal)0.1;
            }
            <td>@tax
            </td>
        </tr>
        <tr>
            <td>
                <b>Discount</b>
            </td>
            @{
                decimal discount = Model.Sum(x => x.Price) * GetDiscount(Model.Count);
            }
            <td>@discount
            </td>
        </tr>
        <tr>
            <td>
                <b>Total</b>
            </td>
            @{
                decimal total = totalbefore + tax - discount;
            }
            <td>@total
            </td>
        </tr>
    </table>
    <div>
    <input type="submit" value="Confirm & Pay" />
    @Html.ActionLink("Cancel", "Index")
    </div>
</form>

